﻿using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbGenreListTest and is intended
    ///     to contain all TmdbGenreListTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbGenreListTest
    {
        /// <summary>
        ///     A test for TmdbGenreList Constructor
        /// </summary>
        [TestMethod]
        public void TmdbGenreListConstructorTest()
        {
            var target = new TmdbGenreList();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for Genres
        /// </summary>
        [TestMethod]
        public void GenresTest()
        {
            var target = new TmdbGenreList();
            var expected = new List<TmdbGenre>();
            target.Genres = expected;
            var actual = target.Genres;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem( @"..\..\TestData\genres.json.txt" )]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbGenreList();
            var jsonContent = File.ReadAllText( "genres.json.txt" );
            var actual = await target.DeserializeJson<TmdbGenreList>( jsonContent );

            Assert.AreEqual( 3, actual.Genres.Count );

            Assert.AreEqual( 28, actual.Genres[ 0 ].Id );
            Assert.AreEqual( "Action", actual.Genres[ 0 ].Name );

            Assert.AreEqual( 12, actual.Genres[ 1 ].Id );
            Assert.AreEqual( "Adventure", actual.Genres[ 1 ].Name );

            Assert.AreEqual( 37, actual.Genres[ 2 ].Id );
            Assert.AreEqual( "Western", actual.Genres[ 2 ].Name );
        }
    }
}